//index.js
//获取应用实例
const app = getApp()
var interval2
Page({
  data: {
    text:'这是一行文字水平滚动效果，在小程序中实现的',
    duration: 0, 
    pace:1,
    // posLeft1: 0,  //水平滚动方法二中left值
    posLeft2: 0,  //水平滚动方法三中left值
    marginLeft: 60  //水平滚动方法三中两条文本之间的间距


  },
  //事件处理函数

  onLoad: function(options) {



  },
  regTap1: function(event) {
    //var that = this
    //console.log()
    //var regsData = event.currentTarget.dataset.id;

    wx.navigateTo({
      url: 'reg_company/reg_company',
    })
    
    
  },
  regTap:function(event){
    var regsData = event.currentTarget.dataset.id;
    console.log(regsData)
  },
  //代理记账跳转
  agency_money:function(event){
    wx.navigateTo({
      url: 'agency_money/agency_money',
    })
  },
  
  //文字滚动效果
  roll2: function (that, txtLength, windowWidth) {
    
    interval2 = setInterval(function () {
      if (-that.data.posLeft2 < txtLength + that.data.marginLeft) {
        that.setData({
          posLeft2: that.data.posLeft2 - that.data.pace
        })
      } else { // 第二段文字滚动到左边后重新滚动
        that.setData({
          posLeft2: 0
        })
        clearInterval(interval2);
        that.roll2(that, txtLength, windowWidth);
      }
    }, 20)
  },

  onShow:function(){

    var that = this;

    var windowWidth = wx.getSystemInfoSync().windowWidth

    wx.createSelectorQuery().select('#txt3').boundingClientRect(function (rect) {
      var txtLength = rect.width;//文字+图标长度
     
      that.setData({
        marginLeft: that.data.marginLeft 

        //marginLeft: txtLength < windowWidth - that.data.marginLeft ? windowWidth - txtLength : that.data.marginLeft
        
        // 102           //273 < 375 - 60 = 315 - 273 = 42                  375 - 273 = 42   赋值 60 
      })
      that.roll2(that, txtLength, windowWidth);
    }).exec()



  },
  onHide:function(){

    clearInterval(interval2)
  }





})